/*-
 * Copyright 2012 Guram Dukashvili
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */
//---------------------------------------------------------------------------
#ifndef __sysconf_h__
#define __sysconf_h__
//---------------------------------------------------------------------------
#ifdef __cplusplus
extern "C" {
#endif
//---------------------------------------------------------------------------
#if defined(_WIN32) && !defined(__WIN32__)
#define __WIN32__ 1
#endif

#if __WIN32__ && !defined(_WIN32_WINNT)
#define _WIN32_WINNT 0x0501     // Указывает, что минимально необходимой версией платформы является Windows XP.
#endif

#if defined(_WIN64) && !defined(__WIN64__)
#define __WIN64__ 1
#endif

#if (__MINGW32__ || __MINGW64__) && !defined(__MINGW__)
#define __MINGW__ 1
#endif

#if __BORLANDC__
#define __PRETTY_FUNCTION__ __FUNC__
#endif

#if __GNUC__
#define __GCC_VER__ (__GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__)
//#if __GCC_VER__ < 460
#define PACKED __attribute__ ((aligned (1)))
//#endif
#endif

#if _MSC_VER
#define __PRETTY_FUNCTION__ __FUNCSIG__
#define LITTLE_ENDIAN 1
#define BIG_ENDIAN 2
#define BYTE_ORDER LITTLE_ENDIAN
#define PACKED

#define S_IRWXU 0000700    /* RWX mask for owner */
#define S_IRUSR 0000400    /* R for owner */
#define S_IWUSR 0000200    /* W for owner */
#define S_IXUSR 0000100    /* X for owner */

#define S_IRWXG 0000070    /* RWX mask for group */
#define S_IRGRP 0000040    /* R for group */
#define S_IWGRP 0000020    /* W for group */
#define S_IXGRP 0000010    /* X for group */

#define S_IRWXO 0000007    /* RWX mask for other */
#define S_IROTH 0000004    /* R for other */
#define S_IWOTH 0000002    /* W for other */
#define S_IXOTH 0000001    /* X for other */

#define S_ISUID 0004000    /* set user id on execution */
#define S_ISGID 0002000    /* set group id on execution */
#ifndef __BSD_VISIBLE
#define S_ISTXT 0001000    /* sticky bit */
#endif

#elif __MINGW__

#define S_IRWXG 0000070    /* RWX mask for group */
#define S_IRGRP 0000040    /* R for group */
#define S_IWGRP 0000020    /* W for group */
#define S_IXGRP 0000010    /* X for group */

#define S_IRWXO 0000007    /* RWX mask for other */
#define S_IROTH 0000004    /* R for other */
#define S_IWOTH 0000002    /* W for other */
#define S_IXOTH 0000001    /* X for other */

#define S_ISUID 0004000    /* set user id on execution */
#define S_ISGID 0002000    /* set group id on execution */
#ifndef __BSD_VISIBLE
#define S_ISTXT 0001000    /* sticky bit */
#endif

#define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
#define BIG_ENDIAN __ORDER_BIG_ENDIAN__
#define BYTE_ORDER __BYTE_ORDER__
#endif

#if _MSC_VER
#define _BIND_TO_CURRENT_CRT_VERSION 1
#define HAVE_STDDEF_H 1
#define HAVE_WINDOWS_H 1
#define HAVE_DIRECT_H 1
#define HAVE_IO_H 1
#define HAVE_SHARE_H 1
#if _MSC_VER >= 1600
#define HAVE_STDINT_H 1
#endif
#define HAVE_MBCTYPE_H 1
#define HAVE_MBSTRING_H 1
#define HAVE__VSNPRINTF 1
#define HAVE__UNLINK 1
#define HAVE__MKDIR 1
#define HAVE__SOPEN 1
#define HAVE__CLOSE 1
#define HAVE__READ 1
#define HAVE__WRITE 1
#define HAVE__ALLOCA 1
#define HAVE_INTRIN_H 1
#define HAVE_FCNTL_H 1
#define HAVE__CHSIZE_S 1
#define HAVE__GET_OSFHANDLE 1
#define HAVE__STAT64 1
#define HAVE__LSEEKI64 1
#define HAVE__STRICOLL 1
#define PATH_DELIM_CHAR '\\'
#define PATH_DELIM "\\"
#define PRIu32 "I32u"
#define PRId32 "I32d"
#define PRIx32 "I32x"
#define PRIX32 "I32X"
#define PRIu64 "I64u"
#define PRId64 "I64d"
#define PRIx64 "I64x"
#define PRIX64 "I64X"
#define PRIuMAX "I64u"
#define PRIdMAX "I64d"
#define PRIxMAX "I64x"
#define PRIXMAX "I64X"
#if _MSC_VER < 1600
typedef signed __int8 int8_t;
typedef unsigned __int8 uint8_t;
typedef signed __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef signed __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef signed __int64 int64_t;
typedef unsigned __int64 uint64_t;
typedef signed __int64 intmax_t;
typedef unsigned __int64 uintmax_t;
#endif
#define HAVE_SYS_TIMEB_H 1
#define HAVE_STRUCT__TIMEB64 1
#define HAVE__FTIME64 1
#elif __MINGW__
#define HAVE_STDDEF_H 1
#define HAVE_WINDOWS_H 1
#define HAVE_DIRENT_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_STDINT_H 1
#define HAVE_UNISTD_H 1
#define HAVE_DIRECT_H 1
#define HAVE_IO_H 1
#define HAVE_SHARE_H 1
#define HAVE_FCNTL_H 1
#define HAVE_MALLOC_H 1
#define HAVE_MBSTRING_H 1
#define HAVE_ANSIDECL_H 1
#define HAVE_SYS_TIME_H 1
#define HAVE_SYS_TIMEB_H 1
#define HAVE_VSNPRINTF 1
#define HAVE__VSNPRINTF 1
#define HAVE__MKDIR 1
#define HAVE_UNLINK 1
#define HAVE__UNLINK 1
#define HAVE_SOPEN 1
#define HAVE__SOPEN 1
#define HAVE_CLOSE 1
#define HAVE__CLOSE 1
#define HAVE__READ 1
#define HAVE__WRITE 1
#define HAVE__ALLOCA 1
#define HAVE_FTRUNCATE 1
#define HAVE_FTIME 1
#define HAVE__GET_OSFHANDLE 1
#define HAVE__STATI64 1
#define HAVE__LSEEKI64 1
#define HAVE_GETTIMEOFDAY 1
#define HAVE__STRICOLL 1
#define HAVE_STRUCT_TIMEB 1
#define PATH_DELIM_CHAR '\\'
#define PATH_DELIM "\\"
#endif

#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__linux__)
#define HAVE_STDDEF_H 1
#define HAVE_STDARG_H 1
#define HAVE_DIRENT_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_STDINT_H 1
#define HAVE_UNISTD_H 1
#define HAVE_FCNTL_H 1
#define HAVE_SYS_PARAM_H 1
#define HAVE_SYS_TIME_H 1
#define HAVE_PTHREAD_H 1
#define HAVE_SEMAPHORE_H 1
#define HAVE_SEM_TIMEDWAIT 1
#define HAVE_NANOSLEEP 1
#define HAVE_SYS_UIO_H 1
#define HAVE_PREAD 1
#define HAVE_PWRITE 1
#define HAVE_READV 1
#define HAVE_WRITEV 1
//#define HAVE_CLOCK_GETTIME 1 // comment for not link rt lib
#define HAVE_GETTIMEOFDAY 1
#define HAVE_TIMEGM 1
#define HAVE_STRCASECMP 1
#define HAVE_SYSCONF 1
#define _FILE_OFFSET_BITS 64
#define _LARGEFILE64_SOURCE 1
#define _THREAD_SAFE 1
#define _REENTRANT 1
#ifdef __linux__
#define HAVE_LINUX_UNISTD_H 1
#define HAVE_SYSCALL_H 1
#define HAVE_FEATURES_H 1
#define HAVE__FETCH_AND_ADD_32 1
#define HAVE__COMPARE_AND_SWAP_32 1
#define HAVE_ENDIAN_H 1
#define __USE_BSD 1
#define _BSD_SOURCE 1
#define _GNU_SOURCE 1
#define _XOPEN_SOURCE 600
//#define _POSIX_SOURCE 1
#else
#define HAVE_PTHREAD_NP_H 1
#define HAVE_SYS_ENDIAN_H 1
#define HAVE_MACHINE_ATOMIC_H 1
#define HAVE_MACHINE_CPU_H 1
#define HAVE_CPU_SPINWAIT 1
#define HAVE_PREADV 1
#define HAVE_PWRITEV 1
#define __BSD_VISIBLE 1
#define HAVE_BE16ENC 1
#define HAVE_BE32ENC 1
#define HAVE_BE64ENC 1
#define HAVE_LE16ENC 1
#define HAVE_LE32ENC 1
#define HAVE_LE64ENC 1
#define HAVE_BE16DEC 1
#define HAVE_BE32DEC 1
#define HAVE_BE64DEC 1
#define HAVE_LE16DEC 1
#define HAVE_LE32DEC 1
#define HAVE_LE64DEC 1
#endif
#define HAVE_SYSCONF 1
#define HAVE_VSNPRINTF 1
#define HAVE_MKDIR 1
#define HAVE_UNLINK 1
#define HAVE_OPEN 1
#define HAVE_CLOSE 1
#define HAVE_FTRUNCATE 1
#define HAVE_HTOBE16 1
#define HAVE_HTOBE32 1
#define HAVE_HTOBE64 1
#define HAVE_LE16TOH 1
#define HAVE_LE32TOH 1
#define HAVE_LE64TOH 1
#define HAVE_BE16TOH 1
#define HAVE_BE32TOH 1
#define HAVE_BE64TOH 1
#define HAVE_HTOLE16 1
#define HAVE_HTOLE32 1
#define HAVE_HTOLE64 1
#define PATH_DELIM_CHAR '/'
#define PATH_DELIM "/"
#endif

#if _MSC_VER < 1600
#define INT32_C(val) val##i32
#define UINT32_C(val) val##ui32
#define INT64_C(val) val##i64
#define UINT64_C(val) val##ui64
#define INTMAX_C(val) val##i64
#define UINTMAX_C(val) val##ui64
#endif

#if _M_X64 || _M_IA64
#define SIZEOF_INTPTR_T 8
#define SIZEOF_VOID_P 8
#define SIZEOF_INTMAX_T 8
#define HAVE_INTPTR_T_EQUAL_INT64_T 1
#define PRIuPTR "I64u"
#define PRIdPTR "I64d"
#define PRIxPTR "I64x"
#define PRIXPTR "I64X"
#ifndef INT64_MAX
#define INT64_MAX 0x7fffffffffffffff
#endif
#define INTPTR_MAX INT64_MAX
#elif _M_IX86
#define SIZEOF_WCHAR_T 2
#define SIZEOF_INTPTR_T 4
#define SIZEOF_VOID_P 4
#define SIZEOF_INTMAX_T 8
#define HAVE_INTPTR_T_EQUAL_INT 1
#define PRIuPTR "I32u"
#define PRIdPTR "I32d"
#define PRIxPTR "I32x"
#define PRIXPTR "I32X"
#ifndef INT32_MAX
#define INT32_MAX 0x7fffffff
#endif
#define INTPTR_MAX INT32_MAX
#elif __MINGW__ || __GNUC__
#define SIZEOF_WCHAR_T __SIZEOF_WCHAR_T__
#if __MINGW64__ || __x86_64__ || __amd64__
#define SIZEOF_INTPTR_T 8
#define SIZEOF_VOID_P 8
#define SIZEOF_INTMAX_T 8
#define HAVE_INTPTR_T_EQUAL_INT 0
#define HAVE_INTPTR_T_EQUAL_INT64_T 1
#elif (__MINGW32__ && !__MINGW64__) || __i386__ || __i586__ || __i686__
#define SIZEOF_INTPTR_T 4
#define SIZEOF_VOID_P 4
#define SIZEOF_INTMAX_T 4
#define HAVE_INTPTR_T_EQUAL_INT 1
#define HAVE_INTPTR_T_EQUAL_INT64_T 0
#else
#error must be defined for arch
#endif
#endif

#if SIZEOF_INTPTR_T == 4
#define INTPTR_C(v) INT32_C(v)
#define UINTPTR_C(v) UINT32_C(v)
#elif SIZEOF_INTPTR_T == 8
#define INTPTR_C(v) INT64_C(v)
#define UINTPTR_C(v) UINT64_C(v)
#else
#error must be defined for arch
#endif
//---------------------------------------------------------------------------
#if __GNUC__
#define __STDC_FORMAT_MACROS 1
#define __STDC_CONSTANT_MACROS 1
#define __always_inline__ __attribute__((always_inline))
#elif _MSC_VER
#define __inline__ __forceinline
#define __always_inline__
#else
#define __inline__ __inline
#define __always_inline__
#endif

//#if __MINGW__
//#define _POSIX 1
//#endif

#if _MSC_VER
//#define _POSIX_ 1
#define _CRT_SECURE_NO_WARNINGS 1
#define _CRT_NONSTDC_NO_WARNINGS 1
#ifndef NDEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#endif
#endif
//---------------------------------------------------------------------------
#if HAVE_FEATURES_H
#include <features.h>
#endif
#include <sys/types.h>
#if HAVE_STDDEF_H
#include <stddef.h>
#endif
#if HAVE_STDARG_H
#include <stdarg.h>
#endif
#if HAVE_ANSIDECL_H
#include <ansidecl.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if HAVE_MALLOC_H
#include <malloc.h>
#endif
#if HAVE_MBSTRING_H
#include <mbstring.h>
#endif
#if HAVE_MBCTYPE_H
#include <mbctype.h>
#endif
#include <locale.h>
#include <wchar.h>
#include <memory.h>
#include <assert.h>
#include <errno.h>
#include <time.h>
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#if HAVE_SYS_TIMEB_H
#include <sys/timeb.h>
#endif
#if HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#if HAVE_STDINT_H
#include <stdint.h>
#endif
#if HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#if HAVE_SYS_UIO_H
#include <sys/uio.h>
#endif
#if HAVE_INTRIN_H
#include <intrin.h>
#endif
#include <sys/stat.h>
#if HAVE_DIRECT_H
#include <direct.h>
#endif
#if HAVE_IO_H
#include <io.h>
#endif
#if HAVE_DIRENT_H
#include <dirent.h>
#endif
#if HAVE_SHARE_H
#include <share.h>
#endif
#if HAVE_FCNTL_H
#include <fcntl.h>
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#if HAVE_PTHREAD_H
#include <pthread.h>
#endif
#if HAVE_PTHREAD_NP_H
#include <pthread_np.h>
#endif
#if HAVE_SEMAPHORE_H
#include <semaphore.h>
#endif
#if HAVE_ENDIAN_H
#include <endian.h>
#endif
#if HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
#endif
#ifdef HAVE_WINDOWS_H
#include <windows.h>
#endif
//---------------------------------------------------------------------------
typedef uint8_t bool;
#define false ((bool) 0)
#define true ((bool) 1)
//---------------------------------------------------------------------------
#ifndef O_DIRECT
#define O_DIRECT 0
#endif
#ifndef O_BINARY
#define O_BINARY 0
#endif
#ifndef O_SYNC
#define O_SYNC 0
#endif
#ifndef O_LARGEFILE
#define O_LARGEFILE 0
#endif
#ifndef O_RANDOM
#define O_RANDOM 0
#endif
#if HAVE__ALLOCA && !defined(alloca)
#define alloca _alloca
#endif
#ifndef ETIMEDOUT
#define ETIMEDOUT 60
#endif
//---------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
// program params
/////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
#define COMPILE_RUNTIME_CHECKS 1
//---------------------------------------------------------------------------
#ifdef __cplusplus
};
#endif
//---------------------------------------------------------------------------
#endif // __config_h__
//---------------------------------------------------------------------------
